﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Pageparkproject.Controllers
{
    public class ProjectController : Controller
    {
        //
        // GET: /Project/
        Pageparkproject.Models.Stories St = new Models.Stories();
        Models.tblSetting setting = Models.Stories.GetPageSetting(); 
        public ActionResult Index(int ?id)
        {
            int cateID = (id ?? 0);
            ViewBag.Cog = St.getListCategoryProject();
            return View(St.projectList(cateID));
        }

        public ActionResult ProjectDetail(int id)
        {
            var project = St.projectGetById(id);
            var nextProject = St.getNextProject(project);
            ViewBag.nextTitle = nextProject.sProjectName;
            ViewBag.nextID = nextProject.PK_iProjectID;
            return View(project);
        }
        public ActionResult ProjectList(string time, string idCategory)
        {
            int? timeStart = null, timeEnd = null, id = null;
            if (!idCategory.Equals("all")) id = int.Parse(idCategory);
            if (!time.Equals("all"))
            {
                timeStart = int.Parse(time.Split('-')[0]);
                timeEnd = !time.Split('-')[1].Equals("present") ? int.Parse(time.Split('-')[1]) : -1;
                if (timeEnd == -1) timeEnd = null;
            }
            return PartialView(St.projectListFilter(id, timeStart, timeEnd));
        }
    }
}
